import management from '../../api/management'
import toast from '../../utils/toast'
const values = {
    name: '',
    mobile: '',
    idcard: '',
    complany: '',
    com_role: '',
    revenue: '',
    property_json: [
        {
            key: "车辆",
            value: "个人名下全款"
        },
        {
            key: "房产",
            value: "个人名下全款"
        },
    ],//资产情况 
    other_json: [
        {
            key: "本地社保",
            value: "缴纳六个月以下"
        },
        {
            key: "公积金",
            value: "缴纳六个月以下"
        },
    ],//其它 
    sesame:'',
    quota:'',
    limit:'',
    purpose: '', //周转用途
    need_money: '',//所需金额
    credit_json: [
        {
            key: "芝麻分",
            value: ""
        },
        {
            key: "花呗额度",
            value: ""
        },
        {
            key: "借呗额度",
            value: ""
        },
        {
            key: "微粒贷额度",
            value: ""
        },
        {
            key: "京东白条额度",
            value: ""
        },
        {
            key: "其他网贷共用额度",
            value: ""
        },
        {
            key: "信用卡额度",
            value: ""
        },
        {
            key: "逾期情况",
            value: ""
        },
        {
            key: "使用过借贷宝吗",
            value: ""
        },
        {
            key: "使用过今借到吗",
            value: ""
        },
    ],//信用情况 
    idcardArr:[],
    handArr:[],
    fundArr:[],
    idcard_images: '',//身份证正反面照片 
    hand_card_images: '',//手持身份证照片
    fund_images: '',//公积金余额截图
    location: '',//位置信息
}

const state = {
	information:{},
    values: JSON.parse(JSON.stringify(values)),
    fields: [
        {
            label: '姓名',
            prop: 'name',
            type: 'input',
            labelWidth: '150',
            placeholder: '请填写姓名',
        },
        {
            label: '手机号',
            prop: 'mobile',
            type: 'number',
            labelWidth: '150',
            placeholder: '请填写手机号',
        },
		
        {
            label: '身份证号',
            prop: 'idcard',
            type: 'input',
            labelWidth: '150',
            placeholder: '请填写身份证号',
        },
        {
            label: '工作单位',
            prop: 'complany',
            type: 'input',
            labelWidth: '150',
            placeholder: '请填写工作单位',
        },
        {
            label: '职位',
            prop: 'com_role',
            type: 'input',
            labelWidth: '150',
            placeholder: '请填写职位',
        },
        {
            label: '收入',
            prop: 'revenue',
            type: 'number',
            labelWidth: '150',
            placeholder: '请填写收入金额',
        },
    ],
    rules: {
        name: [
            {
                required: true,
                message: '请填写姓名',
                trigger: 'blur,change'
            },
        ],
        mobile: [
            {
                required: true,
                message: '请填写手机号',
                trigger: 'blur,change'
            },
			{
				pattern: /^1[0-9]{10}$/g,
				// 正则检验前先将值转为字符串
				transform(value) {
					return String(value);
				},
				message: '请填写正确的手机号'
			},
        ],
        idcard: [
            {
                required: true,
                message: '请填写身份证号',
                trigger: 'blur,change'
            },
			{
				pattern: /^(\d{18,18}|\d{15,15}|\d{17,17}X)$/g,
				// 正则检验前先将值转为字符串
				transform(value) {
					return String(value);
				},
				message: '请填写正确的身份证号'
			},
        ],
        complany: [
            {
                required: true,
                message: '请填写工作单位',
                trigger: 'blur,change'
            },
        ],
        com_role: [
            {
                required: true,
                message: '请填写职位',
                trigger: 'blur,change'
            },
        ],
        revenue: [
            {
                required: true,
                message: '请填写收入金额',
                trigger: 'blur,change'
            },
			{
				pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/g,
				// 正则检验前先将值转为字符串
				transform(value) {
					return String(value);
				},
				message: '请正确填写收入金额'
			},,
        ],

    },
    vehicleList:[
        {
            name: '个人名下全款',
            disabled: false,
        },
        {
            name: '个人名下按揭',
            disabled: false
        },
        {
            name: '配偶名下',
            disabled: false,
        },
        {
            name: '无',
            disabled: false
        }
    ],
    localList: [
        {
            name: '缴纳六个月以下',
            disabled: false,
        },
        {
            name: '缴纳六个月以上',
            disabled: false
        },
        {
            name: '当前断交',
            disabled: false,
        },
        {
            name: '无社保',
            disabled: false
        }
    ],
    fundList:[
        {
            name: '缴纳六个月以下',
            disabled: false,
        },
        {
            name: '缴纳六个月以上',
            disabled: false
        },
        {
            name: '当前断交',
            disabled: false,
        },
        {
            name: '无公积金',
            disabled: false
        }
    ],
    fundFields:[
        {
            label: '周转用途',
            prop: 'purpose',
            type: 'select',
            labelWidth: '150',
            placeholder: '请选择周转用途',
            show:false,
        }, 
        {
            label: '所需金额',
            prop: 'need_money',
            type: 'number',
            labelWidth: '150',
            placeholder: '请填写所需金额',
            name:'元'
        }, 
    ],
    actionSheetList:[],
    creditFields:[
        {
            label: '芝麻分',
            prop: 'sesame',
            type: 'number',
            labelWidth: '150',
            placeholder: '请填写您的芝麻分',
        }, 
        {
            label: '花呗额度',
            prop: 'quota',
            type: 'number',
            labelWidth: '150',
            placeholder: '请填写您的花呗额度',
        }, 
        {
            label: '借呗额度',
            prop: 'limit',
            type: 'number',
            labelWidth: '150',
            placeholder: '请填写您的借呗额度',
        },  
    ],
    particleList:[
        {
            name: '3k以下',
            disabled: false,
        },  
        {
            name: '3k-1w',
            disabled: false,
        }, 
        {
            name: '1w-2w',
            disabled: false,
        }, 
        {
            name: '2w-4w',
            disabled: false,
        }, 
        {
            name: '4w以上',
            disabled: false,
        }, 
        {
            name: '无',
            disabled: false,
        }, 
    ],
    overdueList:[
        {
            name: '1年逾期超过3次或90天',
            disabled: false,
        }, 
        {
            name: '1年逾期少于3次或90天',
            disabled: false,
        },   
        {
            name: '1年内无逾期',
            disabled: false,
        }, 
        {
            name: '从未逾期',
            disabled: false,
        }, 
    ],
    useList:[
        {
            name: '注册使用过',
            disabled: false,
        },   
        {
            name: '只注册过',
            disabled: false,
        }, 
        {
            name: '没注册过',
            disabled: false,
        }, 
    ],
    info:{},
    pitchIndex:0,
    
}
const mutations = {
    //push照片
    IMAGE_PUSH(state,data){
        console.log(data.fullurl);
        console.log(state.values.idcardArr);
     state.values[data.name].push(data.fullurl)
    //  console.log(state.values.idcardArr);
    },
    //删除对应的照片
    IMAGE_SPLICE(state,data){
        state.values[data.name].splice(data.index,1)
    },
    GET_MAP(state,data){
    state.values.location=data
    },
    CHANGE_PITCH(state,index){
       state.pitchIndex=index
    },

}
const actions = {
    GET_DATA({ state }, data) {
        management.userInfoPost().then(res => {
            if (res) {
              
                if(!res.data){
					uni.setStorageSync('flag',false); 
				  }else{
					state.information=res.data
					console.log(state.information,111)
                    uni.setStorageSync('check_status', res.data.check_status);
                    uni.setStorageSync('app_index', res.data.app_index); 
                      if(res.data.check_status==1){
                        uni.setStorageSync('flag',true); 
                        state.info=res.data
                      } else if(res.data.check_status==2){
                       state.values=res.data
                       state.values.sesame=state.values.credit_json[0].value
                       state.values.quota=state.values.credit_json[1].value
                       state.values.limit=state.values.credit_json[2].value
                       if(state.values.idcard_images!=''){
                         let  arr =state.values.idcard_images.split(',');
                         console.log(arr);
                         let list=[]
                         arr.map(item=>{
                            list.push({url:`https://tianhui.kexunyun.cn${item}`})
                             
                         })
                        
                        state.values.idcardArr=arr
                        state.values.idcardList=list
                       } else{
                        state.values.idcardArr=[] 
                       }
                        if(state.values.hand_card_images!=''){
                        let  arr =state.values.hand_card_images.split(',');
                        let list=[]
                        arr.map(item=>{
                           list.push({url:`https://tianhui.kexunyun.cn${item}`})
                            
                        })
                        state.values.handArr=arr
                        state.values.handList=list
                       }else{
                        state.values.handArr=[]  
                       }
                        if(state.values.fund_images!=''){
                        let  arr =state.values.fund_images.split(',');
                        let list=[]
                        arr.map(item=>{
                           list.push({url:`https://tianhui.kexunyun.cn${item}`})
                            
                        })
                        state.values.funddArr=arr
                        state.values.fundList=list
                       } else{
                        state.values.fundArr=[] 
                       }
                        
                      }
					
				  }
                 
            }
        })
    },
    GET_LIST({state}){
        management.purposeList().then(res=>{
            if(res){
                state.actionSheetList=res.data
            }
        })
    },
    SUBMIT_DATA({state,dispath}){
        console.log( state.values);
        if(state.values.idcardArr.length>0){
            state.values.idcard_images=state.values.idcardArr.join(',')
        }
        if(state.values.handArr.length>0){
            state.values.hand_card_images=state.values.handArr.join(',')
        }
        if(state.values.fundArr.length>0){
            state.values.fund_images=state.values.fundArr.join(',')
        }
       
        state.values.credit_json[0].value=state.values.sesame
        state.values.credit_json[1].value=state.values.quota
        state.values.credit_json[2].value=state.values.limit
        management.submitInfo(state.values).then(res=>{
            if(res){
            state.values=JSON.parse(JSON.stringify(values))
            state.pitchIndex=0
            uni.reLaunch({
                url: '/pages/management/waitFor'
            });
            }
        })
    },
    GET_APPLY({state},id){
        management.submitDebt({id:id}).then(res=>{
           if(res){
			   uni.showToast({
			   	title: '申请成功',
			   	icon: 'success',
			   	duration: 2000,
			   		success:()=>{
			   			setTimeout(()=>{
			   				uni.redirectTo({
			   					url: '/pages/management/customer'
			   				});
			   			},500)
			   		}
			   });
          
           }
        })  
    },
	//保存通讯录信息
	SAVE_CONTACTS({state},data){
		console.log(data,'data')
		management.userTxlData({txl:data}).then(res=>{
			console.log(res)
		}) 
	},
	//保存短信
	SAVE_MSG({state},data){
		console.log(data,'data')
		management.userMsgData({msg:data}).then(res=>{
			console.log(res)
		})
	}
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}

